package com.smy.jkds.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * @author z01140
 * @Package: com.smy.jkds.vo
 * @Description:
 * @CreateDate 2021/10/30 18:13
 * @UpdateDate 2021/10/30 18:13
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HeatmapVO {

    String date;
    // 1 - 5 颜色主键变深
    Integer color = 0;
    Integer taskCount = 0;

    public static HeatmapVO getInstance(LocalDate date, Integer taskCount, Integer maxCount){

        HeatmapVO heatmapVO = new HeatmapVO();
        heatmapVO.setDate(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        heatmapVO.setTaskCount(taskCount);

        BigDecimal i = BigDecimal.valueOf(taskCount.doubleValue()).divide(BigDecimal.valueOf(maxCount.doubleValue()), 2, RoundingMode.HALF_UP);
        if (i.compareTo(BigDecimal.ZERO) == 0){
            heatmapVO.setColor(ColorEnum.ONE.color);
        }else if (i.compareTo(BigDecimal.valueOf(0.25D)) <= 0){
            heatmapVO.setColor(ColorEnum.TWO.color);
        }else if (i.compareTo(BigDecimal.valueOf(0.5D)) <= 0){
            heatmapVO.setColor(ColorEnum.THREE.color);
        }else if (i.compareTo(BigDecimal.valueOf(0.75D)) <= 0){
            heatmapVO.setColor(ColorEnum.FOUR.color);
        }else if (i.compareTo(BigDecimal.valueOf(1D)) <= 0){
            heatmapVO.setColor(ColorEnum.FIVE.color);
        }
        return heatmapVO;
    }

    enum  ColorEnum{
        ONE(1,""),
        TWO(2,""),
        THREE(3,""),
        FOUR(4,""),
        FIVE(5,""),
       ;
        private Integer color;
        private String desc;
        ColorEnum(Integer color, String desc){
            this.color = color;
            this.desc = desc;
        }
    }
}
